<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>动态组件与v-once指令</title>
	<script src="vue.js"></script>
</head>
<body>
	
	<!-- 点击button, child-one和child-two 依次显示隐藏 -->
	<!-- 动态组件, <component> 会根据is里面的值, 动态加载组件 -->
	<div id="root">
		<!-- <component :is="type"></component> -->
		<child-one v-if="type === 'child-one'"></child-one>
		<child-two v-if="type === 'child-two'"></child-two>
		<button @click="handleBtnClick">change</button>
	</div>



	<script>
		//v-once 如果内容没有改变,加上之后, 则会直接从内存中去取数据
		
		Vue.component('child-one', {
			template: '<div v-once>child-one</div>'
		})

		Vue.component('child-two', {
			template: '<div v-once>child-two</div>'
		})

		var vm = new Vue({
			el:'#root',
			data: {
				type: 'child-one'
			},
			methods:{
				handleBtnClick: function(){
					this.type = this.type === 'child-one' ? 'child-two' : 'child-one'
				}
			}
		})
	</script>


</body>
</html>